﻿using System;
using System.Diagnostics;
using System.Threading;
using AzureStorageMapper.TableStorage;
using AzureStorageMapper.TableStorage.Attributes;
using AzureStorageMapper.TableStorage.RESTCommunicate;
using AzureStorageMapper.TableStorage.Utils;
using NUnit.Framework;

namespace AzureStorageMapper.Tests.TableStorage.RESTCommunicate
{
    [TestFixture]
    public class TalkToTableStorage_CreateDeleteTableTests
    {
        private TalkToTableStorage _talkToTableStorage;

        [SetUp]
        public void SetUpTest()
        {
            _talkToTableStorage = new TalkToTableStorage(AccountInfo.TableStorageAccountName, AccountInfo.TableStorageAccountKey);
        }

        [Test]
        public void TableCreateDelete_Test()
        {
            TableInfo tInfo = TableUtilities.GetTableInfo(typeof(SampleTableModel));

            Trace.TraceInformation("Creating table '{0}' ...", tInfo.Name);
            _talkToTableStorage.CreateTable(tInfo);

            Trace.TraceInformation("Sleeping for 5 sec ...");
            Thread.Sleep(TimeSpan.FromSeconds(5));

            Trace.TraceInformation("Deleting table '{0}' ...", tInfo.Name);
            _talkToTableStorage.DeleteTable(tInfo);
        }

        [TableModel(Name = "SampleTable")]
        internal class SampleTableModel : TableEntity
        {
            [TableColumn]
            public string ColumnOne { get; set; }

            [TableColumn(Name = "Column2")]
            public int ColumnTwo { get; set; }

            [TableColumn]
            public long ColumnThree { get; set; }

            public SampleTableModel(string partitionKey, string rowKey)
                : base(partitionKey, rowKey)
            {
            }
        }
    }
}
